package com.onlinelearn.websocketservice.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

@Service
public class WebSocketService {
    @Autowired
    private SimpMessagingTemplate messagingTemplate;

    public void sendMessageToUser(Long userId, Object message) {
        messagingTemplate.convertAndSendToUser(
            userId.toString(), 
            "/queue/messages", 
            message
        );
    }

    public void sendMessageToCourse(Long courseId, Object message) {
        messagingTemplate.convertAndSend(
            "/topic/course/" + courseId, 
            message
        );
    }
} 